﻿using System;
using System.Collections.Generic;
using System.Globalization;
using BlogEngine.Core;
using MongoDB.Driver;

namespace BlogEngine.MongoDbProvider
{
    public class PostMongoMapper : IMongoMapper<Post>
    {
        public Document Map(Post entity)
        {
            return new Document();
        }

        public IEnumerable<Post> Map(ICursor documents)
        {
            throw new NotImplementedException();
        }

        public Post Map(Document document)
        {
            var post = new Post
                           {
                               Id = new Guid(document["Id"].ToString()),
                               Author = document["Author"].ToString(),
                               Title = document["Title"].ToString(),
                               Description = document["Description"].ToString(),
                               Content = document["Content"].ToString(),
                               DateCreated = DateTime.Parse(document["Raters"].ToString(), CultureInfo.InvariantCulture),
                               DateModified =
                                   DateTime.Parse(document["Raters"].ToString(), CultureInfo.InvariantCulture),
                               IsPublished = bool.Parse(document["Raters"].ToString()),
                               IsCommentsEnabled = bool.Parse(document["Raters"].ToString()),
                               Raters = int.Parse(document["Raters"].ToString(), CultureInfo.InvariantCulture),
                               Rating = float.Parse(document["Rating"].ToString(), CultureInfo.GetCultureInfo("en-gb")),
                               Slug = document["Slug"].ToString()
                           };

            return post;
        }
    }
}